// 345.反转字符串中的元音字母
package Leetcode_Second_Brush;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

public class Solution345 {
    public String reverseVowels(String s) {
        char[] charArray = s.toCharArray();
        Set<Character> vowel = new HashSet<>();
        Collections.addAll(vowel, 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U');
        int left = 0, right = s.length() - 1;
        while (left < right) {
            while (left < right && !vowel.contains(charArray[left]))
                left++;
            while (left < right && !vowel.contains(charArray[right]))
                right--;
            char temp = charArray[left];
            charArray[left++] = charArray[right];
            charArray[right--] = temp;
        }

        return String.valueOf(charArray);
    }
}
